package com.jt.zxchoujiang.controller;

import com.jt.zxchoujiang.pojo.ChouJiang;
import com.jt.zxchoujiang.pojo.Prize;
import com.jt.zxchoujiang.service.IChouJiangService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class ChouJiangController {

    @Autowired
    private IChouJiangService chouJiangService;

    @RequestMapping("/choujiang")
    public String choujiang(ChouJiang choujiang, Model model){
        String msg = chouJiangService.add(choujiang);
        model.addAttribute("msg",msg);
        return "ok";
    }

    @RequestMapping("/search")
    public String findAll(Model model){
        List<ChouJiang> list = chouJiangService.findAll();
        model.addAttribute("listChoujinag",list);
        return "query";
    }

    @RequestMapping("/addPrize")
    public String addPrize(Prize prize, Model model){
        chouJiangService.addPrize(prize);
        model.addAttribute("msg","增加成功");
        return "ok";
    }

    @RequestMapping("/toPrize")
    public String toPrize(){
        return "prize";
    }

    @RequestMapping("/searchPrize")
    public String findAllPrize(Model model){
        List<Prize> list = chouJiangService.findAllPrize();
        model.addAttribute("listPrize",list);
        return "listPrize";
    }
}
